﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASBCC.Database.Entity;
using ASBCC.Database.Service;
using System.Data;
using ASBCC.Workflow.K2Manager;
using ASBCC.Business;
using Telerik.Web.UI;
using BEGDC.CC.Web.Common;
using BEGDC.Utility.Extensions;


namespace BEGDC.CC.Web.Workflow.Admin
{
    public partial class FlowProcessMyActivity : System.Web.UI.Page
    {
        #region Define
        private ProcessBusiness processBusiness = new ProcessBusiness();
        #endregion

        #region PageLoad
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindProcNameDropdownlist();
                //ucPager.Query();
            }
        }
        #endregion

        #region Event


        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            ucPager.Query();
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)
        {
            Guid id = new Guid(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["MyActivityID"].ToString());
            List<Guid> list = new List<Guid>();
            list.Add(id);
            processBusiness.MoveMyActivity(list);
            ucPager.Refresh();
        }
        #endregion

        #region Function

        protected void ucPager_OnNeedDataSource(object sender, PagerEventArgs e)
        {
            string ownerEn = txtOwner.Text.Trim().SanitizeSqlValue();
            string procName = ddlProcName.SelectedValue;
            string applicationNo = txtApplicationNo.Text.Trim().SanitizeSqlValue();
            int formId = -1;
            //bool resFormId = int.TryParse(txtFormId.Text, out formId);
            //if (!resFormId) formId = -1;

            object count = 0;
            ucPager.DataSource = DatabaseManager.usp3_Select_MyActivity(applicationNo, formId, e.IsLast, "", ownerEn, ucPager.PageIndex, ucPager.PageSize, procName, ref count);
            ucPager.RowsCount = (int)count;
        }

        private void BindProcNameDropdownlist()
        {
            Flow_ProcessTableEntitySet set = Flow_ProcessManager.SelectAll();
            DataTable dt = null;
            if (set != null && set.Tables.Count > 0)
            {
                dt = set.Tables[0];
            }
            //if (dt != null)
            //{
            //    DataRow dr = dt.NewRow();
            //    dr["ProcName"] = "";
            //    dr["ProcDisplayEn"] = "";
            //    dt.Rows.InsertAt(dr, 0);
            //}
            ddlProcName.DataTextField = "ProcDisplayEn";
            ddlProcName.DataValueField = "ProcName";
            ddlProcName.DataSource = dt;
            ddlProcName.DataBind();
        }
        #endregion

        
    }
}
